code source game Bi-a 3D

23.679 lượt xem;
1 using UnityEngine;
2 using
ThreeDPool.EventHandlers;
3 using
ThreeDPool.Managers;
4
5 namespace
ThreeDPool.Controllers
6 {
7     
class InputController : MonoBehaviour
8     {
9         
private void Update()
10         {
11             
if (Input.GetKey(KeyCode.Escape))
12             {
13                 
// game paused
14                 EventManager.Notify(
typeof(GameInputEvent).Name, this, new GameInputEvent() { State = GameInputEvent.States.Paused });
15             }
16
17             
// dont send any input when the game is either paused or in getset state
18             
if (GameManager.Instance.CurrGameState == GameManager.GameState.GetSet ||
19                 GameManager.Instance.CurrGameState == GameManager.GameState.Pause)
20                 
return;
21
22             
float x = 0.0f;
23             
float y = 0f;
24             
if (Input.GetMouseButton(0))
25             {
26                 
// on A or D or left arrow or right arrow or LMB along x are the cue controllers
27                 x = Input.GetAxis(
"Mouse X") - Input.GetAxis("Horizontal");
28                 y = Input.GetAxis(
"Mouse Y");
29             }
30             
else if(Input.GetMouseButtonUp(0))
31             {
32                 
// the LMB is been released
33                 EventManager.Notify(
typeof(GameInputEvent).Name, this, new GameInputEvent() { State = GameInputEvent.States.Release });
34             }
35             
else
36             {
37
38             }
39
40             
// notify the event for the input along x
41             
if(x != 0.0f)
42                 EventManager.Notify(
typeof(GameInputEvent).Name, this, new GameInputEvent() { State = GameInputEvent.States.HorizontalAxisMovement, axisOffset = x });
43  
44             
// notify the event for the input along y
45             
if(y != 0.0f)
46                 EventManager.Notify(
typeof(GameInputEvent).Name, this, new GameInputEvent() { State = GameInputEvent.States.VerticalAxisMovement, axisOffset = y });
47         }
48     }
49 }


Gõ tìm kiếm nhanh...